<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="98px">
      <el-form-item label="检查类型" prop="checkType">
        <el-cascader
          :clearable="true"
          v-model="value"
          :options="typeOptionList"
          :props="{ expandTrigger: 'hover' }"
          @change="handleChange"></el-cascader>
      </el-form-item>
      <!--<el-form-item label="检查类型" prop="checkType">
        <el-cascader
          :clearable="true"
          v-model="value"
          :options="adminTypeOptionList"
          :props="{ expandTrigger: 'hover' }"
          @change="handleChange"></el-cascader>
      </el-form-item>-->
      <el-form-item label="是否存在问题" prop="isProblems">
        <el-select v-model="queryParams.isProblems" clearable placeholder="请选择" style="width: 100%">
          <el-option label="是" value="1" />
          <el-option label="否" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否整改" prop="isRectification">
        <el-select v-model="queryParams.isRectification" clearable placeholder="请选择" style="width: 100%">
          <el-option label="是" value="1" />
          <el-option label="否" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="检查人" prop="personInCharge">
        <el-input
          v-model="queryParams.personInCharge"
          placeholder="请输入检查人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属场站" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入所属场站"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5" v-if="station_btn">
        <router-link :to="{name:'AddInspection',params:{checkType:this.queryParams.checkType,checkObject:this.queryParams.checkObject}}" class="link-type">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ledger:inspection:add']"
        >新增</el-button>
        </router-link>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="inspectionList" :max-height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column label="检查场站" align="left" prop="stationName" width="300"/>
      <el-table-column label="检查日期" align="center" prop="checkDate" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.checkDate | dateString('YYYY-MM-DD') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检查类型" align="center" prop="checkType">
        <template slot-scope="scope">
          <span>{{ typeFormat(scope.row.checkType)}}</span><span v-if="scope.row.checkObject != null && scope.row.checkObject != '' && scope.row.checkObject != undefined">---{{checkObjectFormat(scope.row.checkObject)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否存在问题" align="center" prop="isProblems">
        <template slot-scope="scope">
          <span>{{ isProblemsFormat(scope.row.isProblems)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="检查人" align="left" prop="personInCharge" :show-overflow-tooltip="true"/>
      <el-table-column label="是否整改" align="center" prop="isRectification" >
        <template slot-scope="scope">
          <span>{{ isRectificationFormat(scope.row.isRectification)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link v-if="scope.row.checkType =='0' && scope.row.isBefore == '0'" :to="'/inspection/view/' + scope.row.id" class="link-type">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
            >详细</el-button>
          </router-link>
            <el-button v-if="scope.row.checkType =='1' || (scope.row.checkType =='0' && scope.row.isBefore == '1')"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >详细</el-button>
          <!--<router-link v-if="scope.row.isRectification !='1' && scope.row.checkType =='0' && scope.row.isBefore == '0' && scope.row.isUpdate == 0" :to="'/inspection/edit/' + scope.row.id" class="link-type">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-hasPermi="['ledger:inspection:edit']"
            >修改</el-button>
          </router-link>
          <el-button v-if="scope.row.isRectification !='1' && scope.row.checkType =='1' || (scope.row.isRectification !='1' && scope.row.checkType =='0' && scope.row.isBefore == '1')"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ledger:inspection:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ledger:inspection:remove']"
          >删除</el-button>-->
          <!--<router-link v-if="scope.row.isProblems =='1' && scope.row.checkType =='0' && scope.row.isRectification != 1 && scope.row.isBefore == '0'" :to="'/inspection/edit2/' + scope.row.id" class="link-type">
            <el-button
                       size="mini"
                       type="text"
                       icon="el-icon-edit-outline"
                       @click="handleRectification(scope.row)"
                       v-hasPermi="['ledger:inspection:edit']"
            >整改</el-button>
          </router-link>
          <el-button v-if="scope.row.isProblems =='1' && scope.row.checkType =='1' && scope.row.isRectification != 1 ||(scope.row.isProblems =='1' && scope.row.checkType =='0' && scope.row.isRectification != 1 && scope.row.isBefore == '1')"
                     size="mini"
                     type="text"
                     icon="el-icon-edit-outline"
                     @click="handleRectification(scope.row)"
                     v-hasPermi="['ledger:inspection:edit']"
          >整改</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安全管理监督检查台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="检查日期:" prop="checkDate">
              <el-date-picker clearable size="small" style="width: 200px"
                v-model="form.checkDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择检查日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检查类型:" prop="checkType">{{typeFormat(form.checkType)}}
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="检查大类:" prop="checkObject">
              <el-select v-model="form.checkObject" clearable  placeholder="请选择" >
                <el-option
                  v-for="dict in typeOptions"
                  :key="dict.dictCode"
                  :label="dict.dictLabel"
                  :value="dict.dictCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="检查内容:" prop="checkContent">
          <el-input v-model="form.checkContent" type="textarea" :rows="3" placeholder="请输入检查内容"></el-input>
        </el-form-item>
        <el-form-item label="是否存在问题:" prop="isProblems">
          <el-radio-group v-model="form.isProblems">
            <el-radio
              v-for="dict in dictList"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="存在问题：" prop="existingProblems">
          <el-input v-model="form.existingProblems" type="textarea" :rows="3" placeholder="请输入存在问题"></el-input>
        </el-form-item>
        <el-form-item label="检查人：" prop="personInCharge">
          <el-input v-model="form.personInCharge"   placeholder="请输入检查人" maxlength="15"  show-word-limit></el-input>
        </el-form-item>
        <el-col :span="24">
          <el-form-item label="上传图片:">
            <el-upload
              :multiple="true"
              accept=".jpg, .png, .gif, .bmp, .jpeg"
              :headers="upload.headers"
              :action="upload.url"
              :file-list="form.imgList"
              list-type="picture-card"
              :limit="upload.limit"
              :before-upload="beforeImageUpload"
              :on-exceed="exceedFile"
              :on-success="handlePictureSuccess"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove">
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png/bmp/jpeg文件，且不超过10M</div>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 整改安全管理监督检查台账对话框 -->
    <el-dialog :title="title" :visible.sync="openRectification" width="1000px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="检查日期:" prop="checkDate">{{ form.checkDate | dateString('YYYY-MM-DD') }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检查类型:" >{{typeFormat(form.checkType)}}</el-form-item>
          </el-col>
          <el-col :span="8" v-if="is_show || form.checkType ==='1'">
            <el-form-item label="检查大类:" >{{checkObjectFormat(form.checkObject)}}</el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="检查内容:" prop="checkContent">
          <el-input v-model="form.checkContent" type="textarea" :rows="3" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="存在问题：" prop="existingProblems">
          <el-input v-model="form.existingProblems" type="textarea" :rows="3" :readonly="true" ></el-input>
        </el-form-item>
        <el-form-item label="检查人：" prop="personInCharge">{{form.personInCharge}}</el-form-item>
        <el-form-item label="检查图片：" prop="imgList" class="img" v-if="form.imgList && form.imgList.length > 0 ">
          <ul>
            <li v-for="img in form.imgList" style="text-align: center;">
              <el-image :preview-src-list="srcList" :src="img.url" style="width: 146px;height:146px"></el-image>
            </li>
          </ul>
        </el-form-item>
        <hr/>

        <el-form-item label="整改意见" prop="rectificationOpinion">
          <el-input v-model="form.rectificationOpinion" type="textarea" :rows="3" placeholder="请输入整改意见"></el-input>
        </el-form-item>
        <el-form-item label="整改结果" prop="rectificationResults">
          <el-input v-model="form.rectificationResults" type="textarea" :rows="3" placeholder="请输入整改结果"></el-input>
        </el-form-item>
        <el-row>
        <el-col :span="16">
          <el-form-item label="复查人员:" prop="reinspectionPerson">
            <el-input v-model="form.reinspectionPerson" placeholder="请输入复查人员" maxlength="15"  show-word-limit/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="复查日期:" prop="reinspectionPersonDate">
            <el-date-picker clearable size="small" style="width: 200px"
                v-model="form.reinspectionPersonDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择复查人员签名日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
        <el-col :span="24">
          <el-form-item label="上传图片:">
            <el-upload
              :multiple="true"
              accept=".jpg, .png, .gif, .bmp, .jpeg"
              :headers="upload.headers"
              :action="upload.url"
              :file-list="form.checkImgsList"
              list-type="picture-card"
              :limit="upload.limit"
              :before-upload="beforeImageUpload"
              :on-exceed="exceedFile"
              :on-success="handleCheckPictureSuccess"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleCheckRemove">
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png/bmp/jpeg文件，且不超过10M</div>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="openRectification = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>

    <!-- 详情 -->
    <el-dialog :title="title" :visible.sync="openView" width="800px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5" style="float:right;">
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleViewExport(id)"
          >导出</el-button>
          <el-button
            type="primary"
            icon="el-icon-printer"
            size="mini"
            @click="printPreview()"
          >打印</el-button>
        </el-col>
      </el-row>
      <el-form ref="form" id="print" :model="form" :rules="rules" label-width="120px">
          <div class="div-view">
             <h2>道路货运站（场）安全管理隐患排查治理检查</h2>
            <el-row :gutter="10" class="mb8">
              <span style="float: right;padding-right:10px;line-height: 28px;">{{form.checkDate | dateString('YYYY 年 MM 月 DD 日') }}</span>
            </el-row>
             <table class="sheet_table">
                <tr>
                   <td width="20%;">受检单位</td>
                   <td width="40%;">{{form.stationName}}</td>
                   <td width="20%;">检查人</td>
                   <td width="20%;">{{form.personInCharge}}</td>
                </tr>
               <tr>
                   <td width="20%;">检查类型</td>
                   <td width="40%;">{{typeFormat(form.checkType)}}</td>
                   <td width="20%;">检查大类</td>
                   <td width="20%;">{{checkObjectFormat(form.checkObject)}}</td>
                </tr>
               <tr>
<!--                 <td>参加检查的部门及人员</td>-->
<!--                 <td colspan="3" style="text-align: left;">{{form.checkDeptWorker}}</td>    -->
                 <td>检查内容</td>
                 <td colspan="3" style="text-align: left;">{{form.checkContent}}</td>
               </tr>
               <tr>
                 <td>存在问题</td>
                 <td colspan="3" style="text-align: left;">{{form.existingProblems}}</td>
               </tr>
               <tr v-if="form.imgList && form.imgList.length > 0 ">
                 <td colspan="4">检 查 照 片</td>
               </tr>
               <tr v-if="form.imgList && form.imgList.length > 0 ">
                 <td colspan="4" style="text-align: left;">
                   <ul>
                     <li v-for="img in form.imgList" style="text-align: center;">
                       <el-image :preview-src-list="srcList" :src="img.url" style="width: 100px;height:100px;"></el-image>
                     </li>
                   </ul>
                 </td>
               </tr>
               <tr>
                 <td>整改意见</td>
                 <td colspan="3" style="text-align: left;">{{form.rectificationOpinion}}</td>
               </tr>
               <tr>
                 <td>整改结果</td>
                 <td colspan="3" style="text-align: left;">
                   <div>{{form.rectificationResults}}</div>
                   <div>
                     <span>复查人员签名：{{form.reinspectionPerson}}</span>
                     <span style="margin-left:100px;" v-if="form.reinspectionPersonDate">日期：{{form.reinspectionPersonDate | dateString('YYYY-MM-DD') }}</span>
                     <span style="margin-left:100px;" v-else>日期：</span>
                   </div>
                 </td>
               </tr>
               <tr v-if="form.checkImgsList && form.checkImgsList.length > 0 ">
                 <td colspan="4">复 查 照 片</td>
               </tr>
               <tr v-if="form.checkImgsList && form.checkImgsList.length > 0 ">
                 <td colspan="4" style="text-align: left;">
                   <ul>
                     <li v-for="img in form.checkImgsList" style="text-align: center;">
                       <el-image :preview-src-list="checkSrcList" :src="img.url" style="width: 100px;height:100px;"></el-image>
                     </li>
                   </ul>
                 </td>
               </tr>
             </table>
          </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openView = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInspection, getInspection, delInspection, addInspection, updateInspection, exportInspection,exportInspectionDetail } from "@/api/ledger/inspection";
import { getToken } from "@/utils/auth";
import { getLodop } from '@/utils/C-Lodop/LodopFuncs';
export default {
  name: "Inspection",
  data() {
    var checkObjects = (rule, value, callback) => {
      if (this.form.checkType === '1') {
        if (!value) {
          callback(new Error('请选择检查大类'));
        }else{
          callback()
        }
      }else {
        callback()
      }
    };
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      value: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 安全管理监督检查台账表格数据
      inspectionList: [],
      typeOptions:[],
      typeOptionList:[],
      adminTypeOptions:[],
      adminTypeOptionList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      is_show: false,
      openView: false,
      openRectification: false,
      station_btn: false,
      tableHeight: window.innerHeight - 275,
      //日期范围
      dateRange: [],
      srcList:[],
      checkSrcList:[],
      dictList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stationId: undefined,
        stationName: undefined,
        checkCompany: undefined,
        checkType: undefined,
        checkObject: undefined,
        isProblems: undefined,
        isRectification: undefined,
        personInCharge: undefined,
      },
      // 表单参数
      form: {
      },
      upload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/upload",
        //  文件个数
        limit: 5
      },
      // 表单校验
      rules: {
        checkDate: [
          { required: true, message: "检查日期不能为空", trigger: "blur" }
        ],
        checkType: [
          { required: true, message: "请选择检查类型", trigger: "blur" }
        ],
        checkContent: [
          { required: true, message: "检查内容不能为空", trigger: "blur" }
        ],
        personInCharge: [
          { required: true, message: "检查人不能为空", trigger: "blur" }
        ],
        isProblems: [
          { required: true, message: "请选择是否有问题", trigger: "blur" }
        ],
        existingProblems: [
          { required: true, message: "存在问题不能为空", trigger: "blur" }
        ],
        checkObject: [
          { validator:checkObjects, trigger: "blur" }
        ],
      },
      dialogImageUrl: '',
      dialogVisible: false,
    };
  },
  watch: {
    $route: function(to,from){
      //do something
      this.getList();
      this.resetQuery();
    },
  },
  created() {
    const stationId = this.$route.params && this.$route.params.stationId;
    this.queryParams.stationId=stationId;
    const stationName = this.$route.params && this.$route.params.stationName;
    this.queryParams.stationName=stationName;
    this.getList();

    this.dictList = [{"dictValue":"1","dictLabel":"是"},{"dictValue":"0","dictLabel":"否"}]
    // 场站角色
    this.getDicts2("special_inspection_type",this.queryParams.stationId).then(response => {
      this.typeOptions = response.data;
      const options = [];
      this.typeOptions.map(function (item) {
        options.push({value:item.dictCode,label:item.dictLabel})
      })
      this.typeOptionList = [{value: "0",label: "日常检查"},{value:"1",label:"专项检查",children:options}]
    });
    // 管理角色
    // this.getDicts("special_inspection_type").then(response => {
    //   this.adminTypeOptions = response.data;
    //   const options = [];
    //   this.adminTypeOptions.map(function (item) {
    //     options.push({value:item.dictCode,label:item.dictLabel})
    //   })
    //   this.adminTypeOptionList = [{value: "0",label: "日常检查"},{value:"1",label:"专项检查",children:options}]
    // });

    const roles = this.$store.getters && this.$store.getters.roles;
    for (let rol of roles){
      if ('station'==rol || 'hs_station'==rol){
        this.station_btn=true;
      }
    }
  },
  methods: {
    /** 查询安全管理监督检查台账列表 */
    getList() {
      this.loading = true;
      listInspection(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.inspectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        stationId: undefined,
        checkDate: undefined,
        checkCompany: undefined,
        personInCharge: undefined,
        checkDeptWorker: undefined,
        existingProblems: undefined,
        rectificationOpinion: undefined,
        rectificationResults: undefined,
        reinspectionPerson: undefined,
        reinspectionPersonDate: undefined,
        delFlag: undefined,
        createTime: undefined,
        createId: undefined,
        updateTime: undefined,
        updateId: undefined,
        remark: undefined,
        checkType: undefined,
        checkObject: undefined,
        checkContent: undefined,
        isProblems: undefined,
        isRectification: undefined,
        imgList: [],
        imgs:[],
        checkImgsList: [],
        checkImgs:[],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams)
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.value = [];
      this.queryParams.checkType = undefined;
      this.queryParams.checkObject = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      // this.is_show = false;
      // this.open = true;
      // this.title = "添加安全隐患监督检查台账";
      // this.$router.push({
      //   path: "/inspection/add",
      //   meta: { title: "aaa" }
      // });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInspection(id).then(response => {
        this.form = response.data;
        console.log(this.form)
        if (this.form.checkType === '1'){
          this.is_show = true;
        }
        if (this.form.checkType === '0'){
          this.is_show = false;
        }
        const imgs = [];
        this.form.imgList.map(function (item) {
          imgs.push(item.url);
        });
        const checkImgs = [];
        this.form.checkImgsList.map(function (item) {
          checkImgs.push(item.url);
        });
        this.form.checkObject = parseInt(this.form.checkObject);
        this.form.checkImgs = checkImgs;
        this.form.imgs = imgs;
        this.open = true;
        this.title = "修改安全生产事故隐患排查治理";
      });
    },
    /** 整改按钮操作 */
    handleRectification(row) {
      this.reset();
      const id = row.id || this.ids
      getInspection(id).then(response => {
        this.form = response.data;
        const imgs = [];
        this.form.imgList.map(function (item) {
          imgs.push(item.url);
        });
        const checkImgs = [];
        this.form.checkImgsList.map(function (item) {
          checkImgs.push(item.url);
        });
        this.form.imgs = imgs;
        this.form.checkImgs = checkImgs;
        this.openRectification = true;
        this.form.isRectification = "1";
        this.title = "整改安全生产事故隐患排查治理";
      });
    },
    handleView(row) {
      this.reset();
      const id = row.id || this.ids
      getInspection(id).then(response => {
        this.id = row.id;
        this.form = response.data;
        const imgs = [];
        this.form.imgList.map(function (item) {
          imgs.push(item.url);
        });
        const checkImgs = [];
        this.form.checkImgsList.map(function (item) {
          checkImgs.push(item.url);
        });
        this.srcList = imgs;
        this.checkSrcList = checkImgs;
        this.openView = true;
        this.title = "安全生产事故隐患排查治理详情";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.checkType === '0'){
            this.form.checkObject = '';
          }
          if (this.form.id != undefined) {
            updateInspection(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.openRectification = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addInspection(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除该条安全生产事故隐患排查治理的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInspection(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有安全生产事故隐患排查治理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInspection(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 导出详情操作 */
    handleViewExport(id) {
      this.$confirm('是否确认导出该条安全生产事故隐患排查治理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInspectionDetail(id);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    beforeImageUpload(file){
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 10MB!')
        return false
      }
    },
    exceedFile(files, fileList) {
      let msg = `最多只能上传${this.upload.limit}个图片`;
      this.$message.warning(msg)
    },
    //图片上传
    handleRemove(file, fileList) {
      this.form.imgs.splice(this.form.imgs.indexOf(file.url),1);
    },
    //复查图片上传
    handleCheckRemove(file, fileList) {
      this.form.checkImgs.splice(this.form.imgs.indexOf(file.url),1);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handlePictureSuccess(response, file) {
      this.form.imgs.push(response.fileName);
    },
    handleCheckPictureSuccess(response, file) {
      this.form.checkImgs.push(response.fileName);
    },
    // 检查类型
    typeFormat(val) {
      if (val === '0')
        return "日常检查"
      if (val === '1')
        return "专项检查"
    },
    // 检查大类
    objectFormat(val) {
      if (val === '0')
        return "叉车"
      if (val === '1')
        return "消防设备"
      else
        return ""
    },
    // 是否存在问题
    isProblemsFormat(val) {
      if (val === '0')
        return "否"
      if (val === '1')
        return "是"
    },
    checkObjectFormat(value) {
      return this.selectDictLabel2(this.adminTypeOptions, value);
    },
    checkTypeChange(){
      const checkTypeChange = this.form.checkType;
      this.form.checkObject = undefined;
      if (checkTypeChange == '1'){
        this.is_show = true
      }else {
        this.is_show = false;
      }
    },
    // 是否整改
    isRectificationFormat(val) {
      if (val === '0')
        return "否"
      if (val === '1')
        return "是"
      else
        return "-"
    },
    handleChange(value) {
      if (value.length >0 && value.length ==1){
        this.queryParams.checkType = value[0]
        this.queryParams.checkObject = undefined;
      }else if (value.length >0 && value.length ==2){
        this.queryParams.checkType = value[0]
        this.queryParams.checkObject = value[1]
      }else {
        this.queryParams.checkType = undefined;
        this.queryParams.checkObject = undefined;
      }
    },
    // 打印
    printPreview() {
      this.CreateOneFormPage()
      LODOP.PREVIEW() //打印预览
    },
    CreateOneFormPage() {
      LODOP = getLodop()
      if (LODOP == undefined){
       return  this.openView = false;
      }
      //样式
      var body = this.global.inspection_style +'<body>' + document.getElementById('print').innerHTML + '</body>'
      // LODOP.PRINT_INIT('安全教育活动台账详情') //打印初始化
      // LODOP.SET_PRINT_STYLE('FontSize', 18) //设置对象风格
      // LODOP.SET_PRINT_STYLE('Bold', 1) ////设置对象风格
      // LODOP.ADD_PRINT_TEXT(50, 521, 130, 39, this.description) //增加纯文本项
      // LODOP.SET_PRINT_PAGESIZE(0, 2000, 2000, 'A4') //设定纸张大小
      // LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '55%')//设置缩放
      // LODOP.SET_PREVIEW_WINDOW(2, 2, 0, 0, 0, '')//设置窗口
      // LODOP.ADD_PRINT_HTM(88, 20, 2000, 2000, body) //增加超文本项
      LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A4");
      LODOP.SET_PRINT_STYLE("FontSize", 12);
      LODOP.ADD_PRINT_HTM(5, 5, "100%", "100%", body);
      LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1);//横向时的正向显示
    }
  }
};
</script>
<style scoped>
  .img ul{
    padding: 0;
  }
  .img ul li{
    float:left;
    width:20%;
    list-style:none;
    width: 146px;
    margin-right: 2%;
  }
  @import '../../../assets/styles/ledger_style.scss';
</style>

